package com.jnzc.ocr.rest.app.shop.controller.app;

import com.google.common.collect.Lists;
import com.jnzc.ocr.common.bean.Page;
import com.jnzc.ocr.common.bean.PageResult;
import com.jnzc.ocr.common.vo.UserVo;
import com.jnzc.ocr.dependencies.rest.base.BaseController;
import com.jnzc.ocr.serv.shop.api.ShopRefundApi;
import com.jnzc.ocr.serv.shop.api.ShopRefundSaleApi;
import com.jnzc.ocr.serv.shop.consts.ShopRefundConsts;
import com.jnzc.ocr.serv.shop.entity.ShopOrder;
import com.jnzc.ocr.serv.shop.entity.ShopRefund;
import com.jnzc.ocr.serv.shop.filter.ShopOrderFilter;
import com.jnzc.ocr.serv.shop.filter.ShopRefundFilter;
import com.jnzc.ocr.serv.shop.vo.ShopRefundSaleCreateVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author zhangcm
 * @version 1.0, 2017-11-26
 */
@Api(tags = {"app - 销售退款接口"})
@RestController
@RequestMapping("/app/refundSale")
public class AppRefundSaleController extends BaseController {

    @Autowired
    private ShopRefundSaleApi shopRefundSaleApi;

    @Autowired
    private ShopRefundApi shopRefundApi;

    @ApiOperation(value = "销售退款记录")
    @GetMapping("/search")
    public PageResult<ShopRefund> search(Page page){
        UserVo userVo = super.get();
        ShopRefundFilter filter = new ShopRefundFilter();
        filter.setShopId(userVo.getShopId());
        filter.setType(ShopRefundConsts.TYPE_SALE);
        filter.setOrderBy("create_time desc");
        return shopRefundApi.search(filter, page.getPageNo(), page.getPageSize());
    }

    @ApiOperation(value = "生成")
    @PostMapping("")
    public void create(@RequestBody ShopRefundSaleCreateVo createVo){
        UserVo userVo = super.get();
        shopRefundSaleApi.create(createVo, userVo.getShopId());
    }

}
